
#include <stdio.h>
#include "STLOG.h"
#include "STL_TcpClientMgr.h"
#include <unistd.h>
#include <memory>

using namespace STL;
int index1 = 0;
int index2 = 0;
int index3 = 0;

int main(int argc, char *argv[])
{
    STL_TcpClientMgr::getInstance()->setConnectCallback([](int socket, std::string ip, uint16_t port)
                                                        {
                                                            stlog_debug("(%d)socket[%d] Connected", index1++, socket);
                                                            std::string get = "GET / HTTP/1.1\r\nHost: 192.168.1.42:8099\r\nUser-Agent: yjkthddx/1.0.0\r\nAccept: */*\r\n\r\n";
                                                            STL_TcpClientMgr::getInstance()->sendData(socket, get);
                                                        });
    STL_TcpClientMgr::getInstance()->setDataCallback([](int socket, std::shared_ptr<std::string> sp_data)
                                                     {
                                                         stlog_debug("(%d)socket[%d] onData", index2++, socket);
                                                         //  stlog_debug("socket[%d] recv[%s]", socket, sp_data->c_str());
                                                         STL_TcpClientMgr::getInstance()->closeTcpConnect(socket);
                                                     });
    STL_TcpClientMgr::getInstance()->setDisconnectCallback([](int socket)
                                                           { stlog_debug("(%d)socket[%d] Disconnect", index3++, socket); });

    for (int i = 0; i < 1000000; i++)
    {
        // if (i % 100 == 0)
        //     sleep(1);
        int socket = STL_TcpClientMgr::getInstance()->createTcpConnect("192.168.1.13", 8099);
    }

    int index = 0;
    while (1)
    {
        printf("%d...\n", index++);
        sleep(1);
    }
    return 0;
}
